/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.dataset.r3000;
import java.util.*;

public class R3000Entry implements Comparable<R3000Entry> {
		public GregorianCalendar cal = new GregorianCalendar();
		public long bitMap = 0;
		
		public R3000Entry() {
			
		}
		
		public R3000Entry(String line) {
			if (line.length() < 8)
				return;
			StringTokenizer st = new StringTokenizer(line);
			String date = st.nextToken();
			cal = new GregorianCalendar();
			cal.set(Calendar.YEAR, Integer.parseInt(date.substring(0,4)));
			cal.set(Calendar.MONTH, Integer.parseInt(date.substring(4,6))-1);
			cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date.substring(6,8)));
			while (st.hasMoreTokens()) {
				int run = Integer.parseInt(st.nextToken());
				bitMap += (long)Math.pow(2,run);
				//System.out.println("bitmap=" + bitMap);
			}
		}
		
		public String getDateString() {
			String temp = "" + cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH)+1;
			if (month < 10)
				temp += "0";
			temp += month;			
			int day = cal.get(Calendar.DAY_OF_MONTH);
			if (day < 10)
				temp += "0";
			temp += day;
			return temp;
		}
		
		public String toString() {
			String temp = "" + cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH)+1;
			if (month < 10)
				temp += "0";
			temp += month;			
			int day = cal.get(Calendar.DAY_OF_MONTH);
			if (day < 10)
				temp += "0";
			temp += day;			
			for (int i = 1; i <= 24; i++) {
				if ((bitMap & (int)Math.pow(2,i)) == (int)(Math.pow(2,i)))
					temp += " " + i;
			}
			return temp;
		}
		
		public int compareTo(R3000Entry e) {
			try {
				if (e == null)
					return -1;
				long ts1 = cal.getTime().getTime();
				long ts2 = e.cal.getTime().getTime();
				if (ts1 > ts2)
					return 1;
				if (ts1 < ts2)
					return -1;
				return 0;
			}
			catch (Exception E) {
				E.printStackTrace();
				return -1;	
			}
		}
	}